#include <lcthw/linear_list.h>
#include <lcthw/dbg.h>
#include "minunit.h"

static int cell_method(int *e)
{
    printf(" %d\n", *e);
    return 0;
}

SqList *L = NULL;

char *test_create()
{
    L = InitList();
    mu_assert(L != NULL, "Failed to create list");

    return NULL;
}

int i1 = 10;
int i2 = 20;
int i3 = 30;

char *test_insert()
{
    int rc = ListInsert(L, 1, i1);
    mu_assert(rc == 0, "Failed to insert element");

    rc = ListInsert(L, 2, i2);
    mu_assert(rc == 0, "Failed to insert element");

    rc = ListInsert(L, 1, i3);
    mu_assert(rc == 0, "Failed to insert element");

    return NULL;
}

char *test_get()
{
    int e;
    int rc = GetElem(L, 2, &e);
    mu_assert(rc == 0, "Failed to get element");

    return NULL;
}

char *test_locate()
{
    int rc = LocateElem(L, 30);
    printf("LocateElem: element found at index %d\n", rc);
    return NULL;
}

char *test_traverse()
{
    int rc = ListTraverse(L, cell_method);
    return NULL;
}

char *test_delete()
{
    int e;
    int rc = ListDelete(L, 2, &e);
    mu_assert(rc == 0, "Failed to delete element");

    return NULL;
}

char *all_tests()
{
    mu_suite_start();

    mu_run_test(test_create);
    mu_run_test(test_insert);
    mu_run_test(test_traverse);
    mu_run_test(test_get);
    mu_run_test(test_locate);
    mu_run_test(test_delete);
    mu_run_test(test_traverse);
/**/
    return NULL;
}

RUN_TESTS(all_tests);